﻿// =================================================================== 
// Module说明
//====================================================================
// 创建时间：2018-12-13 12:49:25
// 负责人：lvsc
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq.Expressions;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using OF.Component.Factory;
using OF.Component.DTO;
using System.Linq;

namespace OF.Component.BLL
{
	
	/// <summary>
	/// 扩展
	/// </summary>
	public partial class FormFieldOperate
	{
        /// <summary>
    	/// 根据断言条件获取单个
    	/// </summary>
        public static FormFieldInfo QuerySingle(Expression<Func<FormFieldInfo, bool>> predicate)
        {
            return dal.QuerySingle(predicate);
        }
        
        /// <summary>
    	/// 根据断言条件获获取列表
    	/// </summary>
        public static IList<FormFieldInfo> QueryList(Expression<Func<FormFieldInfo, bool>> predicate)
        {
            return dal.QueryList(predicate);
        }

        /// <summary>
        /// 获取字段列表
        /// </summary>
        /// <param name="cfgId"></param>
        /// <returns></returns>
        public static IList<FormFieldDto> GetFormFieldRelaedList(int cfgId)
        {
            IList<FormFieldDto> list = new List<FormFieldDto>();
            FormFieldDto obj = null;
            IList<FormFieldRelaInfo> relaList = FormFieldRelaOperate.QueryList(a => a.BizTypeCityRelaID == cfgId && a.IsActive == 1);
            IList<FormFieldInfo> flist = FormFieldOperate.QueryList(a => a.IsActive == 1);
            foreach (var item in flist)
            {
                int sort = 0;
                int rid = 0;
                var li = relaList.Where(a => a.FormFieldID == item.FormFieldID).ToList();
                if (li.Count>0)
                {
                    sort = li[0].FieldSort;
                    rid = li[0].RelaID;
                }
                FormFieldDto ffobj = new FormFieldDto
                {
                    FieldDesc = item.FieldDesc,
                    FieldID = item.FieldID,
                    FieldName = item.FieldName,
                    FieldConstraint = item.FieldConstraint,
                    FieldSort = sort,
                    FieldType = item.FieldType,
                    FormFieldID = item.FormFieldID,
                    RelaID = rid
                };
                list.Add(ffobj);
            }
            return list;
        }
	}
}